package xyz.penghaonan.p2plib.helper.service;

import android.app.NotificationManager;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;

import xyz.penghaonan.p2plib.P2PManager;

public class MainService extends Service {
    public MainService() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        updateNotification();
        return new ServiceBinder(this);
    }

    public void updateNotification() {
        if (P2PManager.getConfig() != null) {
            startForeground(P2PManager.getConfig().getServiceNotificationId(), P2PManager.getConfig().getServiceNotification());
        }
    }

    @Override
    public boolean onUnbind(Intent intent) {
        stopForeground(true);
        return super.onUnbind(intent);
    }
}